home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c,comp.unix.aix
- Subject: Re: Help: write() to a socket hangs unless there's a newline
- Followup-To: comp.unix.aix,comp.unix.programmer
- Date: Tue, 12 Mar 96 19:02:58 GMT
- Organization: none
- Message-ID: <826657378snz@genesis.demon.co.uk>
- References: <5r68cae4wm.fsf@ritz.mordor.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <5r68cae4wm.fsf@ritz.mordor.com>
- benjamin@ritz.mordor.com "Joseph Thomas" writes:
-
- >I realize this is not a direct C question, but it does have to do with
- >streams, and I tend to think the expertise to answer this is here:
-
- You're more likely to find the expertise in the appropriate newsgroup e.g.
- comp.unix.programmer. (comp.unix.aix readers please bear with me, this is
- directed at the comp.lang.c cross-post).
-
- >I've opened a socket, and connected it to another. I'm using write() to
- >send a message through, ex:
-
- Neither sockets not Unix system calls such as write() are part of the
- C language so it is not appropriate to discuss them in comp.lang.c.
- There is nothing here that relates to C streams.
-
- >write(sock_fd, "Hello world", strlen("Hello world"));
- >
- >When I do this, the message gets through to the other socket, but the
- >write() call hangs in the process that executed it.
- >
- >However, if I send it as:
- >
- >write(sock_fd, "Hello world\n", strlen("Hello world\n"));
- >
- >It doesn't hang, but I have a newline I don't want at the other end.
-
- That looks very odd. Make sure write() is prototyped in your system (and
- you are including such a prototype) or you are forcing the 3rd argument
- to a suitable type.
-
- >In addition, for some reason, between the next write()-->read() that I
- >try, I read() two null strings before I actually get the next
- >message (this may be something particular to sockets?)
-
- More evidence that the length (3rd) argument is not being passed correctly.
-
- >I've tried using fflush(sock_fd),
-
- Evidence that the function declarations aren't prototyped or that you aren't
- including the relevant header files. Prototypes would have caught the fact
- that this illegally passes a sock_fd value (probably int) to a standard
- function that requires a FILE * value. fflush() flushes the buffering within
- the C standard library which doesn't exist for file descriptors.
-
- Maybe comp.lang.aix readers can shed more light on this. Please note
- follow-ups directed away from comp.lang.c.
-
- >but that causes a broken pipe for
- >some reason. Can anyone say what gives here?
-
- fflush(integer value) results in undefined behaviour - anything can happen.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-